/**
 * 
 */
package com.massyframework.beanskin.launcher.scanning.maven;

import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;

/**
 * @author huangkh
 *
 */
public class MavenArtifactUtil {

	/**
	 * 满足安全策略下执行处理
	 * @param <T>
	 * @param action {@link PrivilegedExceptionAction}
	 * @return {@link T}
	 * @throws IOException
	 */
	static <T> T doIo(PrivilegedExceptionAction<T> action) throws IOException {
        try {
            return AccessController.doPrivileged(action);
        } catch (PrivilegedActionException e) {
            try {
                throw e.getCause();
            } catch (IOException | RuntimeException | Error e1) {
                throw e1;
            } catch (Throwable t) {
                throw new UndeclaredThrowableException(t);
            }
        }
    }
}
